home *** CD-ROM | disk | FTP | other *** search
/ Aminet 25 / Aminet 25 (1998)(GTI - Schatztruhe)[!][Jun 1998].iso / Aminet / misc / emu / atari800_tr.lzh / pia.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-01-29  |  3.0 KB  |  179 lines

  1. #include <stdio.h>
  2.  
  3. #include "atari.h"
  4. #include "cpu.h"
  5. #include "pia.h"
  6. #include "platform.h"
  7. #include "sio.h"
  8. #include "mem.h"
  9.  
  10. static char *rcsid = "$Id: pia.c,v 1.20 1997/09/30 thor,david Exp $";
  11.  
  12. UBYTE PACTL;
  13. UBYTE PBCTL;
  14. UBYTE PORTA;
  15. UBYTE PORTB;
  16. UBYTE PORTA_mask = 0xff;
  17. UBYTE PORTB_mask = 0xff;
  18.  
  19.  
  20. extern UWORD regPC;
  21.  
  22. extern int CommandIndex,DataIndex,TransferStatus,ExpectedBytes;
  23.  
  24.  
  25. mtype PIA_PACTLR(void)
  26. {
  27.   return PACTL;
  28. }
  29.  
  30. mtype PIA_PBCTLR(void)
  31. {
  32.   return PBCTL;
  33. }
  34.  
  35. mtype PIA_PORTAR(void)
  36. {
  37.   return (PORTA & (~PORTA_mask)) | (Atari_PORT(0) & PORTA_mask);
  38. }
  39.  
  40. mtype PIA_PORTBR(void)
  41. {
  42.   switch (machine)
  43.     {
  44.     case Atari :
  45.       return (Atari_PORT(1) & PORTB_mask);
  46.     case AtariXL :
  47.     case AtariXE : 
  48.       return (PORTB & (~PORTB_mask)) | PORTB_mask;
  49.       /*
  50.       return PORTB = (PORTB & (~PORTB_mask)) | PORTB_mask;
  51.       */
  52.       break;
  53.     default :
  54.       printf ("Fatal Error in pia.c: PIA_GetByte(): Unknown machine\n");
  55.       Atari800_Exit (FALSE, 1);
  56.       break;
  57.     }
  58.   return 0xff;
  59. }  
  60.  
  61.  
  62. int PIA_PORTAW(mtype byte)
  63. {
  64.   if (!(PACTL & 0x04)) {
  65.     PORTA_mask = ~byte;
  66.   }
  67.   else PORTA=byte;
  68.  
  69.   return FALSE;
  70. }
  71.  
  72. int PIA_PORTBW(mtype byte)
  73. {
  74.   if (!(PBCTL & 0x04)) {
  75.     PORTB_mask = ~byte;
  76.     byte=PORTB;
  77.     return FALSE;
  78.   }
  79.  
  80.   switch (machine) {
  81.   case Atari :
  82.     PORTB = byte;
  83.     break;
  84.  
  85.   case AtariXE :
  86.     byte|=PORTB_mask;   
  87.     /* A special hack....  */
  88.     if (byte==0)  break;
  89.  
  90.     SelectXEBank(byte);
  91.     /* l"auft hier hinein */
  92.   case AtariXL :
  93.     byte|=PORTB_mask;    
  94.     /* A special hack....  */
  95.     if (byte==0)  break; 
  96.     
  97.  
  98.     /*
  99.      * Enable/Disable OS ROM 0xc000-0xcfff and 0xd800-0xffff
  100.      *
  101.      */
  102.        if (byte & 0x01) 
  103.          EnableOs();
  104.      else DisableOs();
  105.  
  106.     /*
  107.      * Enable/Disable XL Basic 
  108.      */
  109.        if (byte & 0x02)
  110.      DisableBasic();
  111.        else EnableBasic();
  112.  
  113.     /*
  114.      * Enable/Disable Selftest
  115.      */
  116.       if (byte & 0x80)
  117.     DisableSelftest();
  118.       else EnableSelftest();
  119.  
  120.     PORTB = byte;
  121.  
  122. #ifdef DEBUG
  123.     printf ("PortB PutByte = %08x, Mask=%08x PBCTL=%08x \n",byte,PORTB_mask,PBCTL);
  124. #endif
  125.  
  126.     break;
  127.   default :
  128.     printf ("Fatal Error in pia.c: PIA_PutByte(): Unknown machine\n");
  129.     Atari800_Exit (FALSE, 1);
  130.     break;
  131.   }
  132.  
  133.   return FALSE;
  134. }
  135.  
  136. int PIA_PACTLW(mtype byte)
  137. {
  138.   PACTL = byte;
  139.   /*
  140.   if (PACTL & 0x04)
  141.     PIA_PORTAW(PORTA); 
  142.   */
  143.  
  144.   return FALSE;
  145. }
  146.  
  147. int PIA_PBCTLW(mtype byte)
  148. {
  149.   /* This code is part of the serial I/O emulation */
  150.   if ((PBCTL ^ byte) & 0x08) { /* The command line status has changed */
  151.     SwitchCommandFrame((byte & 0x08)?(0):(1));
  152.   }
  153.   PBCTL = byte;
  154.   /*
  155.   if (PBCTL & 0x04)
  156.     PIA_PORTBW(PORTB);
  157.   */
  158.  
  159.   return FALSE;
  160. }
  161.  
  162.  
  163. void Init_PIA(int *argc, char *argv[],int base)
  164. {
  165.   PORTA = 0xff;
  166.   PORTB = 0xff;
  167.   PORTA_mask = 0xff;
  168.   PORTB_mask = 0xff;
  169.   SetHW(base+_PORTA,0xff03,&PIA_PORTAR,&PIA_PORTAW);
  170.   SetHW(base+_PORTB,0xff03,&PIA_PORTBR,&PIA_PORTBW);
  171.   SetHW(base+_PACTL,0xff03,&PIA_PACTLR,&PIA_PACTLW);
  172.   SetHW(base+_PBCTL,0xff03,&PIA_PBCTLR,&PIA_PBCTLW);
  173.   DisableBasic();
  174.   EnableOs();
  175.   DisableSelftest();
  176.   if (machine==AtariXE)
  177.     SelectXEBank(0xff);
  178. }
  179.